from paddleocr import PaddleOCR, draw_ocr

your_det_model_dir = "pretrain_models/ch_PP-OCR_V3_det_inference/"
your_rec_model_dir = "pretrain_models/rec_ppocr_v3_distillation_inference/"
your_rec_char_dict_path = "int_dict.txt"

# The path of detection and recognition model must contain model and params files
ocr = PaddleOCR(
    det_model_dir=f"{your_det_model_dir}",
    rec_model_dir=f"{your_rec_model_dir}",
    rec_char_dict_path=f"{your_rec_char_dict_path}",
    use_angle_cls=True,
)
img_path = "image/data2/20221117110546_4632.png"
result = ocr.ocr(img_path, cls=True)
for idx in range(len(result)):
    res = result[idx]
    for line in res:
        print(line)

# draw result
from PIL import Image

# result = result[0]
# image = Image.open(img_path).convert('RGB')
# boxes = [line[0] for line in result]
# txts = [line[1][0] for line in result]
# scores = [line[1][1] for line in result]
# im_show = draw_ocr(image, boxes, txts, scores, font_path='/path/to/PaddleOCR/doc/fonts/simfang.ttf')
# im_show = Image.fromarray(im_show)
# im_show.save('result.jpg')
